package com.example.hanfu;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.hanfu.collect.HisActivity;
import com.example.hanfu.login.LoginActivity;
import com.example.hanfu.login.LoginState;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class PersonalFragment extends Fragment {



    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_dashboard, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        LoginState loginState=new LoginState();
        super.onViewCreated(view, savedInstanceState);
        if(loginState.getLogin_state()==0){
            new AlertDialog.Builder(getContext())
                    .setTitle("提示")
                    .setMessage("请先登录")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //已登录
                            Intent score = new Intent(getContext(), LoginActivity.class);//窗口对象
                            startActivity(score);
                        }}).show();
        }
        Button history=view.findViewById(R.id.history);
        Button collect=view.findViewById(R.id.collect);
        TextView textView=view.findViewById(R.id.name);
        textView.setText(loginState.getUserName());
        history.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent open=new Intent(getContext(), HisActivity.class)
                        .putExtra("table","history");
                startActivity(open);
            }
        });
        collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent open=new Intent(getContext(), HisActivity.class)
                        .putExtra("table","collect");
                startActivity(open);
            }
        });
    }
}